﻿using CMS.ViewModel;
using MahApps.Metro.Controls;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CMS.View
{
    /// <summary>
    /// OutputCargoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OutputCargoWindow : MetroWindow
    {
        public OutputCargoWindow()
        {
            InitializeComponent();
            Loaded += (s, e) =>
            {
                var vm = DataContext as OutputCargoViewModel;
                if(vm == null)return;
                var list = new RecordProvider().Select().FindAll(item=>item.CargoId==vm.Cargo.Id);//添加findall条件可以找到指定的id不然显示的是总数量
                if (list == null) return;
                var inputCount = list.FindAll(item=>item.RecoredType==true).Sum(item=>item.Number);
                var outputCount=list.FindAll(item => item.RecoredType == false).Sum(item=>item.Number);
               var sumCount=inputCount-outputCount;
                vm.Sum=sumCount;
            };
        }
    }
}
